home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / btclss12.lha / ButClass11 / ButClassTest.c < prev    next >
C/C++ Source or Header  |  1995-11-14  |  7KB  |  279 lines

  1. #include <proto/exec.h>
  2. #include <proto/intuition.h>
  3. #include <proto/bgui.h>
  4. #include <proto/keymap.h>
  5.  
  6. #include <libraries/bgui.h>
  7. #include <libraries/bgui_macros.h>
  8.  
  9. #include <clib/alib_protos.h>
  10.  
  11. #include <boopsi/ButClass.h>
  12.  
  13. #ifdef _DCC
  14. #include <lib/Misc.h>
  15. #endif
  16.  
  17. #include <stdio.h>
  18.  
  19. /*
  20. **  Gadget ID
  21. **/
  22. #define GD_TITLE        0
  23. #define GD_CLIPMODE     1
  24. #define GD_JUSTIFY      2
  25. #define GD_CLIPJUST     3
  26. #define GD_SETTABLE     4
  27. #define GD_STRING       5
  28. #define GD_PEN_SLIDER   6
  29. #define GD_BACK_SLIDER  7
  30.  
  31. #define GAD_CNT         8
  32.  
  33. /*
  34. **  Library
  35. **/
  36. struct Library *BGUIBase=NULL;
  37. struct Library *KeymapBase=NULL;
  38.  
  39. /*
  40. **  Screen data
  41. **/
  42. struct Screen   *Scr=NULL;
  43.  
  44. /*
  45. **  Object ptr
  46. **/
  47. Object          *WO_Test=NULL;
  48. struct Window   *TestWnd=NULL;
  49. Object          *TestGad[ GAD_CNT ];
  50.  
  51. /*
  52. **  ButClass data
  53. **/
  54. Class           *ButClass=NULL;
  55. Object          *But1=NULL;
  56. Object          *But2=NULL;
  57. Object          *Clipbut=NULL;
  58.  
  59. /*
  60. **  TAG for map.
  61. **/
  62. ULONG   String2But[] = { STRINGA_TextVal, BUT_Label, TAG_END };
  63. ULONG   Slider2ButPen[] = { SLIDER_Level,  BUT_LabelPen, TAG_END };
  64. ULONG   Slider2ButBack[] = { SLIDER_Level,  FRM_BackPen, TAG_END };
  65.  
  66.  
  67.  
  68.  
  69. int main( int argc, char **argv )
  70. {
  71. ULONG           Sig;
  72. BOOL            running=TRUE;
  73. ULONG           rc, t=0;
  74. ULONG           c1=0;
  75.  
  76.     /*
  77.     **  Open the bgui.library
  78.     **/
  79.     if( !( BGUIBase=OpenLibrary( "bgui.library", 39L ) ))
  80.     {
  81.         printf("Can't open bgui.library v39!\n");
  82.         return(30);
  83.     }
  84.  
  85.     /*
  86.     **  Open the keymap.library
  87.     **/
  88.     if( !(KeymapBase=OpenLibrary( "keymap.library", 0L ) ))
  89.     {
  90.         printf("Can't open keymap.library\n");
  91.         CloseLibrary( BGUIBase );
  92.         return(30);
  93.     }
  94.  
  95.     /*
  96.     **  Init. of the ButClass
  97.     **/
  98.     if( !(ButClass=InitButClass()) )
  99.     {
  100.         printf("InitButClass() failed!!\n");
  101.         CloseLibrary( BGUIBase );
  102.         return(30);
  103.     }
  104.  
  105.     /*
  106.     **  Locking screen (for have the number of color) (see bellow)
  107.     **/
  108.     if( !(Scr = LockPubScreen( "Workbench" ) ))
  109.     {
  110.         printf("Can't lock screen\n");
  111.         FreeButClass( ButClass );
  112.         CloseLibrary( BGUIBase );
  113.         CloseLibrary( KeymapBase );
  114.         return(30);
  115.     }
  116.  
  117.  
  118.     /*
  119.     **  Create window..
  120.     **/
  121.     WO_Test= WindowObject,
  122.             WINDOW_Title,           "ButClass test",
  123.             WINDOW_AutoAspect,      TRUE,
  124.             WINDOW_RMBTrap,         TRUE,
  125.             WINDOW_CloseOnEsc,      TRUE,
  126.             WINDOW_ScaleWidth,      20,
  127.             WINDOW_MasterGroup,
  128.  
  129.             VGroupObject, VOffset(4), HOffset(4), Spacing(4),
  130.  
  131.             /*
  132.             **  Title ( with Justification mode ;-).
  133.             **/
  134.             StartMember,
  135.                 TestGad[ GD_TITLE ] = ButObject( ButClass ),
  136.                             GA_ID,                  GD_TITLE+1,
  137.                             NeXTFrame,
  138.                             BUT_ClipText,           TRUE,
  139.                             BUT_Justify,            TRUE,
  140.                             BUT_Label,              BSEQ_J "ButClass" BSEQ_J " 1.2" BSEQ_J " (C) Doguet Emmanuel" BSEQ_J,
  141.                             BUT_LabelPen,           2,
  142.                             BUT_SelectedLabelPen,   2,
  143.                             FRM_BackFill,           FILL_RASTER,
  144.                     EndObject,
  145.             EndMember,
  146.  
  147.             /*
  148.             **  ClipText
  149.             **/
  150.             StartMember, VGroupObject, FrameTitle("ClipText"), NeXTFrame, VOffset(2), HOffset(4+4), BOffset(4), Spacing(4),
  151.                 StartMember,
  152.                     TestGad[ GD_CLIPMODE ] = ButClip( ButClass, "The button can be smaller than the text width !", GD_CLIPMODE ),
  153.                 EndMember,
  154.             EndObject, FixMinHeight, EndMember,
  155.  
  156.             /*
  157.             **  Justify
  158.             **/
  159.             StartMember, HGroupObject, FrameTitle("Justify"), NeXTFrame, VOffset(2), HOffset(4+4), BOffset(4), Spacing(4),
  160.                 StartMember,
  161.                     TestGad[ GD_JUSTIFY ] = ButJustify( ButClass, "_Contact me" BSEQ_J "at:" , GD_JUSTIFY ),
  162.                 EndMember,
  163.             EndObject, FixMinHeight, EndMember,
  164.  
  165.             /*
  166.             **  ClipText and Justify
  167.             **/
  168.             StartMember, HGroupObject, FrameTitle("ClipText + Justify"), NeXTFrame, VOffset(2), HOffset(4+4), BOffset(4), Spacing(4),
  169.                 StartMember,
  170.                     TestGad[ GD_CLIPJUST ] = ButClipJust( ButClass, BSEQ_J "manu@ramses.fdn.org" BSEQ_J "or" BSEQ_J "2:320/104.64" BSEQ_J, GD_CLIPJUST ),
  171.                 EndMember,
  172.             EndObject, FixMinHeight, EndMember,
  173.  
  174.             /*
  175.             **  Settable label, colors...
  176.             **/
  177.             StartMember, VGroupObject, FrameTitle("Label is settable..."), NeXTFrame, VOffset(2), HOffset(4+4), BOffset(4), Spacing(4),
  178.  
  179.                 StartMember,
  180.                     TestGad[ GD_SETTABLE ] = ButClip( ButClass, "Nothing", GD_SETTABLE ),
  181.                 EndMember,
  182.  
  183.                 StartMember,
  184.                     TestGad[ GD_STRING ] = String( NULL, "Nothing", 256, GD_STRING ),
  185.                 EndMember,
  186.  
  187.                 StartMember,
  188.                     TestGad[ GD_PEN_SLIDER ] = HorizSlider( "Pen:", 0, (1<<Scr->BitMap.Depth)-1, 1, GD_PEN_SLIDER ),
  189.                 EndMember,
  190.  
  191.                 StartMember,
  192.                     TestGad[ GD_BACK_SLIDER ] = HorizSlider( "Back:", 0, (1<<Scr->BitMap.Depth)-1, 0, GD_BACK_SLIDER ),
  193.                 EndMember,
  194.  
  195.             EndObject, FixMinHeight, EndMember,
  196.  
  197.  
  198.         EndObject,              // End of Main VGroup
  199.  
  200.         EndObject;              // End of MasterGroup
  201.  
  202.  
  203.     GadgetKey( WO_Test, TestGad[ GD_JUSTIFY ], "c" );
  204.  
  205.  
  206.     if( !WO_Test )
  207.         printf("Failed to create window..\n");
  208.     else
  209.     {
  210.  
  211.         // Map String contents to button
  212.         AddMap( TestGad[ GD_STRING ], TestGad[ GD_SETTABLE ], String2But );
  213.  
  214.         // Map sliders to button (color pen and background
  215.         AddMap( TestGad[ GD_PEN_SLIDER ], TestGad[ GD_SETTABLE ], Slider2ButPen );
  216.         AddMap( TestGad[ GD_BACK_SLIDER ], TestGad[ GD_SETTABLE ], Slider2ButBack );
  217.  
  218.         /*
  219.         **  Open window  and get it's Mask.
  220.         **/
  221.         TestWnd=WindowOpen( WO_Test );
  222.         
  223.         GetAttr( WINDOW_SigMask, WO_Test, &Sig );
  224.  
  225.         /*
  226.         **  Do until close window...
  227.         **/
  228.         if( TestWnd )
  229.  
  230.         do {
  231.  
  232.             Wait( Sig );
  233.  
  234.             while (( rc = HandleEvent( WO_Test )) != WMHI_NOMORE )
  235.             {
  236.                 switch ( rc ) {
  237.                         case    WMHI_CLOSEWINDOW:   running = FALSE;
  238.                                                     break;
  239.                 }
  240.             }
  241.  
  242.         }while ( running );
  243.  
  244.     }
  245.  
  246.  
  247.  
  248.     /*
  249.     **  Dispose window
  250.     **/
  251.     if( WO_Test)
  252.         DisposeObject( WO_Test );
  253.  
  254.     /*
  255.     **  Dispose ButClass
  256.     **/
  257.     if( ButClass )
  258.         FreeButClass( ButClass );
  259.  
  260.     /*
  261.     **  Unlock screen
  262.     **/
  263.     if( Scr )
  264.         UnlockPubScreen( NULL, Scr );
  265.  
  266.     CloseLibrary( BGUIBase );
  267.     CloseLibrary( KeymapBase );
  268.  
  269. }
  270.  
  271.  
  272. #ifdef _DCC
  273. int wbmain( struct WBStartup *w )
  274. {
  275.     OpenConsole("CON:0/100//100/ButClassTest output/AUTO");
  276.     return(main(0,0));
  277. }
  278. #endif
  279.